package com.etc.controller;

import com.etc.dao.PaidDao;
import com.etc.dao.UserDao;
import com.etc.entity.Cinema;
import com.etc.entity.Movie;
import com.etc.entity.Paid;
import com.etc.service.CinemaService;
import com.etc.util.CommonMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;

/**
 * Created by Administrator on 2019/5/23.
 */
@Controller
public class Admin {
    @Autowired
    CinemaService cinemaService;
    @Autowired
    UserDao userDao;
    @Autowired
    PaidDao paidDao;
    @RequestMapping("index")
    public String index() {
        return "views/index";
    }

    @GetMapping("console/{day}")
    @ResponseBody
    public CommonMessage console1(HttpServletRequest request, @PathVariable("day") Integer day) {
        CommonMessage cm=new CommonMessage();
        List list=userDao.findAll();
        request.setAttribute("usernum",list.size());
        List<Paid> list1= null;
        if (day>0){
            list1= paidDao.findByday(day);

        }else {
            list1= paidDao.findAll();

        }
        BigDecimal total=new BigDecimal(0);
        for(Paid l:list1){
            total= total.add(l.getPayprice());
        }
        request.setAttribute("recordnum",list1.size());
        request.setAttribute("total",total);
        cm.setMsg(String.valueOf(total));
        cm.setCode(list1.size());
        return cm;
    }
    @GetMapping("console")
    public String console(HttpServletRequest request) {
        List list=userDao.findAll();
        request.setAttribute("usernum",list.size());
        List<Paid> list1= paidDao.findAll();
        BigDecimal total=new BigDecimal(0);
        for(Paid l:list1){
        total=total.add(l.getPayprice());
        }
        request.setAttribute("recordnum",list1.size());
        request.setAttribute("total",total);
        return "views/console";
    }
    @RequestMapping("userlist")
    public String userlist() {
        return "views/userlist";
    }
    @RequestMapping("cinemalist")
    public String cinemalist(HttpServletRequest request) {
        List<Cinema> list = cinemaService.findAllcname();
        request.getSession().setAttribute("pd", list);
        List<Movie> list1=cinemaService.showAddList();
        request.getSession().setAttribute("pdmovie", list1);
        return "views/cinemalist";
    }
    @RequestMapping("movielist")
    public String movielist() {
        return "views/movielist";
    }

    @RequestMapping("recordlist")
    public String recordlist() {
        return "views/recordlist";
    }

    @RequestMapping("tellogin")
    public String telLogin() {
        return "tellogin";
    }

    @RequestMapping("namelogin")
    public String nameLogin() {
        return "namelogin";
    }

    @RequestMapping("register")
    public String Register() {
        return "register";
    }
    @RequestMapping("loginOut")
    public String loginOut() {
        return "loginOut";
    }
}

